[...slug].vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <!-- 店铺商品列表 @zjf-2020-12-30 -->
  2. <template>
  3. <div class="self_background">
  4. <StoreHeaderCat ref="headercat" @sendGoodsName="sendGoodsName"/>
  5. <div
  6. class="sld_store_goods_list clearfix"
  7. :class="{ skeleton_sld_store_goods_list: firstLoading }"
  8. >
  9. <!-- 左侧分类 start -->
  10. <div
  11. class="left_cat_wrap"
  12. v-show="firstLoading ? true : storeData.cat.length"
  13. >
  14. <template
  15. v-for="(item, index) in firstLoading
  16. ? skeletonData.category
  17. : storeData.cat"
  18. :key="index"
  19. >
  20. <dl
  21. :class="{
  22. store_cat_item: true,
  23. on: !(item.openFlag != undefined && !item.openFlag),
  24. }"
  25. >
  26. <dt class="grade_one_cat">
  27. <router-link
  28. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item.innerLabelId"
  29. >
  30. {{ item.innerLabelName }}
  31. </router-link>
  32. <i
  33. v-if="item.children.length"
  34. class="more"
  35. @click="toggleOpenFlag(index)"
  36. ></i>
  37. </dt>
  38. <dd
  39. v-if="
  40. item.children.length &&
  41. !(item.openFlag != undefined && !item.openFlag)
  42. "
  43. >
  44. <router-link
  45. v-for="(item_child, index_child) in item.children"
  46. :key="index_child"
  47. :to="'/store/goods/'+ calcProductName(storeName) +'_v-'+ vid + '_c-' + item_child.innerLabelId"
  48. >
  49. {{ item_child.innerLabelName }}
  50. </router-link>
  51. </dd>
  52. </dl>
  53. </template>
  54. </div>
  55. <!-- 左侧分类 end -->
  56. <!-- 右侧商品 start -->
  57. <div
  58. :class="{
  59. right_goods_wrap: true,
  60. fr: storeData.cat.length,
  61. no_cate_goods_wrap: !storeData.cat.length,
  62. }"
  63. >
  64. <div class="store_goods_search_nav">
  65. <span :class="{ active: sort == 0 }" >{{
  66. L["综合"]
  67. }}</span>
  68. <div class="sld_store_goods_total_num">
  69. {{ L["共"] }} {{ storeData.goods.pagination.total
  70. }} {{ L["件相关商品"] }}
  71. </div>
  72. </div>
  73. <ul class="sld_store_goods_list_wrap">
  74. <li
  75. v-for="(item, index) in firstLoading
  76. ? skeletonData.goods
  77. : storeData.goods.list"
  78. :key="index"
  79. >
  80. <div class="sld_goods_img">
  81. <router-link
  82. target="_blank"
  83. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  84. >
  85. <img :src="item.goodsImage" style="display: block" />
  86. </router-link>
  87. </div>
  88. <div class="sld_goods_name_wrap">
  89. <router-link
  90. target="_blank"
  91. :to="'/goods/detail/'+ calcProductName(item.goodsDefaultName) +'_'+ item.defaultProductId"
  92. :title="item.goodsName"
  93. v-html="item.goodsName"
  94. class="sld_goods_name"
  95. >
  96. </router-link>
  97. </div>
  98. <p class="clearfix">
  99. <span class="sld_goods_price fl"
  100. ><em>{{
  101. item.goodsMoney == null ? "Contact us to give you an individual quote" : item.goodsMoney
  102. }}</em></span
  103. >
  104. </p>
  105. <div class="promotion_tag">
  106. <template v-if="item.activityList && item.activityList.length">
  107. <div style="display: flex">
  108. <div
  109. v-for="(item_activity, index_activity) in item.activityList"
  110. :key="index_activity"
  111. >
  112. <span class="promotion_tag_text">{{
  113. item_activity.promotionName
  114. }}</span>
  115. </div>
  116. </div>
  117. </template>
  118. <button
  119. class="sld_collect_wrap fr flex_row_center_center"
  120. :class="{ collect_active: item.isFollowGoods }"
  121. @click="collect(item.defaultProductId, item.isFollowGoods)"
  122. >
  123. <img
  124. src="/goods/collection.png"
  125. alt=""
  126. v-show="item.isFollowGoods == true"
  127. style="width: 20px; height: 20px"
  128. />
  129. <img
  130. src="/goods/no_collection.png"
  131. alt=""
  132. v-show="item.isFollowGoods == false"
  133. style="width: 20px; height: 20px"
  134. />
  135. {{ L["收藏"] }}
  136. </button>
  137. </div>
  138. </li>
  139. </ul>
  140. <!-- 分页 start -->
  141. <div class="flex_row_center_center sld_pagination">
  142. <el-pagination
  143. @current-change="handleCurrentChange"
  144. v-model:currentPage.sync="pagitionCurrent"
  145. :page-size="storeData.goods.pagination.pageSize"
  146. layout="prev, pager, next"
  147. :total="storeData.goods.pagination.total"
  148. :hide-on-single-page="true"
  149. >
  150. </el-pagination>
  151. </div>
  152. <!-- 分页 end -->
  153. </div>
  154. <!-- 右侧商品 end -->
  155. <SldLoginModal
  156. v-if="loginModalVisibleFlag"
  157. @closeLoingModal="closeLoingModal"
  158. />
  159. <!-- 空页面 start-->
  160. <SldCommonEmpty
  161. v-if="!firstLoading && !storeData.goods.list.length"
  162. totalWidth="979"
  163. totalHeight="700"
  164. paddingTop="200"
  165. />
  166. <!-- 空页面 end-->
  167. </div>
  168. </div>
  169. </template>
  170. <script setup>
  171. import { ElMessage, ElPagination } from "element-plus";
  172. // import { lang_zn } from "@/assets/language/zh";
  173. import { getCurLanguage } from '@/composables/common.js';
  174. import { useFiltersStore } from "@/store/filter.js";
  175. const filtersStore = useFiltersStore();
  176. const proxy = getCurrentInstance();
  177. const route = useRoute();
  178. // const L = lang_zn;
  179. const L = getCurLanguage();
  180. const firstLoading = ref(true); //是否第一次加载
  181. const router = useRouter();
  182. const storeData = reactive({ cat: [], goods: { list: [], pagination: {} } }); //店铺数据,cat:店铺分类,goods:店铺商品列表
  183. const sort = ref(0); //0:默认/综合;1、销量从高到底;3、价格从低到高;4、价格从高到低;5、人气从高到低
  184. const headercat = ref(null); //获取dom的ref,名字同名
  185. const loginModalVisibleFlag = ref(false); //登录弹框是否显示,默认不显示
  186. const skeletonData = reactive({ category: [], goods: [] });
  187. const SEOinfo = reactive({
  188. seoTitle: "Products",
  189. seoDesc: "",
  190. seoKeywords: "",
  191. });
  192. //动态页面数据
  193. const vid = ref();
  194. const currentPage = ref(1); //分页——当前页
  195. const categoryId = ref(); //分类id
  196. const keyword = ref(); //搜索关键词
  197. const pagitionCurrent = ref(1)
  198. const storeName = ref('')
  199. //接收店铺名称
  200. const sendGoodsName = (val) => {
  201. storeName.value = val
  202. }
  203. const clacRouteParams = () => {
  204. if (calcUrlPagination(route.path)) {
  205. currentPage.value = calcUrlPagination(route.path)
  206. }
  207. if (calcUrlShopId(route.path)) {
  208. vid.value = calcUrlShopId(route.path)
  209. }
  210. if (calcUrlCatId(route.path)) {
  211. categoryId.value = calcUrlCatId(route.path);
  212. }
  213. if (calcUrlKeywords(route.path)) {
  214. keyword.value = calcUrlKeywords(route.path);
  215. }
  216. proxy.refs.headercat.setVid(calcUrlShopId(route.path));
  217. getStoreGoodsList();
  218. getStoreCatData();
  219. };
  220. watch(
  221. () => currentPage.value,
  222. (nv, ov) => {
  223. if (nv != ov) {
  224. pagitionCurrent.value = Number(nv)
  225. }
  226. }
  227. );
  228. //根据切换数据,改变SEO
  229. const setSEO = () => {
  230. if (categoryId.value == "") {
  231. useHead({
  232. title: "Products",
  233. meta: [
  234. {
  235. name: "description",
  236. content: "Products",
  237. },
  238. {
  239. name: "keywords",
  240. content: "Products",
  241. },
  242. ],
  243. });
  244. return;
  245. }
  246. for (let i in storeData.cat) {
  247. if (storeData.cat[i].innerLabelId == categoryId.value) {
  248. SEOinfo.seoTitle = storeData.cat[i].seoInfo.seoTitle;
  249. SEOinfo.seoDesc = storeData.cat[i].seoInfo.seoDesc;
  250. SEOinfo.seoKeywords = storeData.cat[i].seoInfo.seoKeywords;
  251. break;
  252. } else {
  253. for (let j in storeData.cat[i].children) {
  254. if (storeData.cat[i].children[j].innerLabelId == categoryId.value) {
  255. SEOinfo.seoTitle = storeData.cat[i].children[j].seoInfo.seoTitle;
  256. SEOinfo.seoDesc = storeData.cat[i].children[j].seoInfo.seoDesc;
  257. SEOinfo.seoKeywords =
  258. storeData.cat[i].children[j].seoInfo.seoKeywords;
  259. }
  260. }
  261. }
  262. }
  263. useHead({
  264. title: SEOinfo.seoTitle,
  265. meta: [
  266. {
  267. name: "description",
  268. content: SEOinfo.seoDesc,
  269. },
  270. {
  271. name: "keywords",
  272. content: SEOinfo.seoKeywords,
  273. },
  274. ],
  275. });
  276. };
  277. const initSkeletonData = () => {
  278. for (let i = 0; i < 5; i++) {
  279. skeletonData.category.push({
  280. innerLabelId: "",
  281. innerLabelName: "",
  282. openFlag: true,
  283. children: [
  284. { innerLabelId: "", innerLabelName: "0" },
  285. { innerLabelId: "", innerLabelName: "0" },
  286. { innerLabelId: "", innerLabelName: "0" },
  287. ],
  288. });
  289. }
  290. for (let i = 0; i < 8; i++) {
  291. skeletonData.goods.push({
  292. defaultProductId: "",
  293. goodsImage: "",
  294. goodsPrice: "",
  295. saleNum: "",
  296. activityList: [],
  297. isFollowGoods: false,
  298. });
  299. }
  300. };
  301. //获取店铺分类数据
  302. const getStoreCatData = async () => {
  303. const { data: value } = await useFetchRaw(
  304. apiUrl + "v3/seller/front/store/storeCategory?storeId=" + vid.value
  305. );
  306. const res = value._rawValue;
  307. if (res.state == 200) {
  308. storeData.cat = res.data;
  309. }
  310. setSEO();
  311. };
  312. //获取店铺商品列表
  313. const getStoreGoodsList = async () => {
  314. let param = {};
  315. let key = "";
  316. param.storeId = vid.value;
  317. key += vid;
  318. param.current = currentPage.value;
  319. key += currentPage.value;
  320. if (categoryId.value) {
  321. param.storeInnerLabelId = categoryId.value;
  322. key += categoryId.value;
  323. }
  324. if (keyword.value) {
  325. param.keyword = keyword.value;
  326. key += keyword.value;
  327. }
  328. // param.pageSize = 6;
  329. const { data: value, pending: pending } = await useFetchRaw(
  330. apiUrl + "v3/goods/front/goods/goodsList",
  331. { params: param, key: key, headers:{Authorization:'Bearer ' + filtersStore.getToken }}
  332. );
  333. const res = value._rawValue;
  334. if (!pending._rawValue) {
  335. firstLoading.value = false;
  336. }
  337. if (res.state == 200) {
  338. storeData.goods = res.data;
  339. }
  340. };
  341. const toggleOpenFlag = (key) => {
  342. storeData.cat[key].openFlag =
  343. storeData.cat[key].openFlag != undefined
  344. ? !storeData.cat[key].openFlag
  345. : false;
  346. };
  347. //分页切换/前往指定页面
  348. const handleCurrentChange = (val) => {
  349. currentPage.value = val;
  350. let path = "/store/goods/"+ calcProductName(storeName.value)+"_v-"+ vid.value +"_p-" + val
  351. if(keyword.value && !categoryId.value){
  352. path += "_k-" +keyword.value
  353. }
  354. else if(keyword.value && categoryId.value){
  355. path += "_c-" + categoryId.value +"_k-" +keyword.value
  356. }
  357. else if(!keyword.value && categoryId.value){
  358. path += "_c-" + categoryId.value
  359. }
  360. router.push({
  361. path: path
  362. });
  363. };
  364. watch(categoryId, (newValue, oldValue) => {
  365. if (newValue != oldValue) {
  366. setSEO();
  367. }
  368. });
  369. //收藏功能
  370. const collect = (defaultProductId, isFollowGoods) => {
  371. if (filtersStore.getLoginFlag) {
  372. //收藏功能
  373. let params = {
  374. productIds: defaultProductId,
  375. isCollect: !isFollowGoods,
  376. };
  377. post("v3/member/front/followProduct/edit", params).then((res) => {
  378. if (res.state == 200) {
  379. ElMessage.success(res.msg);
  380. storeData.goods.list.map((storeGoodsItem) => {
  381. if (storeGoodsItem.defaultProductId == defaultProductId) {
  382. storeGoodsItem.isFollowGoods = !storeGoodsItem.isFollowGoods;
  383. }
  384. });
  385. } else {
  386. ElMessage.error(res.msg);
  387. }
  388. });
  389. } else {
  390. //未登录的话提示登录
  391. loginModalVisibleFlag.value = true;
  392. }
  393. };
  394. const closeLoingModal = () => {
  395. loginModalVisibleFlag.value = false;
  396. };
  397. onMounted(() => {
  398. setTimeout(() => {
  399. sldStatEvent({ behaviorType: 'spv', storeId: vid.value ,pageUrl: defaultUrl + router.currentRoute.value.path, referrerPageUrl: apiUrl });
  400. }, 3000)
  401. initSkeletonData();
  402. nextTick(() => {
  403. clacRouteParams();
  404. });
  405. });
  406. </script>
  407. <style lang="scss" scoped>
  408. @use "@/assets/style/store/goodsList.scss" as *;
  409. @use "@/assets/style/theme.scss" as *;
  410. .el-pager li.active {
  411. color: $colorMain;
  412. cursor: default;
  413. }
  414. .el-pager li:hover {
  415. color: $colorMain;
  416. }
  417. .sld_pagination {
  418. margin: 20px 0 20px 0;
  419. }
  420. .store_goods_search_nav {
  421. cursor: pointer;
  422. }
  423. </style>